glTF 2.0 loader
This crate is intended to load [glTF 2.0], a file format designed for the
efficient runtime transmission of 3D scenes. The crate aims to provide
rustic utilities that make working with glTF simple and intuitive.
# Installation
Add `gltf` version 0.13 to your `Cargo.toml`.
```toml
[dependencies.gltf]
version = "0.13"
```
# Examples
## Basic usage
Walking the node hierarchy.
```
# fn run() -> Result<(), Box> {
# use gltf::Gltf;
let gltf = Gltf::open("examples/Box.gltf")?;
for scene in gltf.scenes() {
for node in scene.nodes() {
println!(
"Node #{} has {} children",
node.index(),
node.children().count(),
);
}
}
# Ok(())
# }
# fn main() {
# let _ = run().expect("runtime error");
# }
```
## Import function
Reading a glTF document plus its buffers and images from the
file system.
```
# fn run() -> Result<(), Box> {
let (document, buffers, images) = gltf::import("examples/Box.gltf")?;
assert_eq!(buffers.len(), document.buffers().count());
assert_eq!(images.len(), document.images().count());
# Ok(())
# }
# fn main() {
# let _ = run().expect("runtime error");
# }
```
### Note
This function is provided as a convenience for loading glTF and associated
resources from the file system. It is suitable for real world use but may
not be suitable for all real world use cases. More complex import scenarios
such downloading from web URLs are not handled by this function. These
scenarios are delegated to the user.
You can read glTF without loading resources by constructing the [`Gltf`]
(standard glTF) or [`Glb`] (binary glTF) data structures explicitly.
[glTF 2.0]: https://www.khronos.org/gltf
[`Gltf`]: struct.Gltf.html
[`Glb`]: struct.Glb.html
[`Node`]: struct.Node.html
[`Scene`]: struct.Scene.html